package javax.realtime;

public class MemoryParameters implements java.lang.Cloneable {

	public static final long NO_MAX = Long.MAX_VALUE;
	
	private long maxMemoryArea;
	private long maxImmortal;
	private long allocationRate;
	
	public MemoryParameters(long maxMemoryArea, long maxImmortal)
	{
		this(maxMemoryArea, maxImmortal, NO_MAX);
	}
	
	public MemoryParameters(long maxMemoryArea, long maxImmortal, long allocationRate)
	{
		if(maxMemoryArea < 0) throw new IllegalArgumentException();
		if(maxImmortal < 0) throw new IllegalArgumentException();
		if(allocationRate < 0) throw new IllegalArgumentException();
		this.maxMemoryArea = maxMemoryArea;
		this.maxImmortal = maxImmortal;
		this.allocationRate = allocationRate;
	}
	
	public Object clone()
	{
		MemoryParameters copy;
		try
		{
			copy = (MemoryParameters)super.clone();
			return copy;
		}
		catch (CloneNotSupportedException ex)
		{
			throw new InternalError("Clone not supported");
		}
	}
	
	public long getAllocationRate()
	{
		return allocationRate;
	}
	
	public long getMaxImmortal()
	{
		return maxImmortal;
	}
	
	public long getMaxMemoryArea()
	{
		return maxMemoryArea;
	}
	
	public void setAllocationRate(long allocationRate)
	{
		if(allocationRate < 0) throw new IllegalArgumentException();
		this.allocationRate = allocationRate;
	}
	
	public boolean setAllocationRateIfFeasible(long allocationRate)
	{
		setAllocationRate(allocationRate);
		return true;
	}
	
	public boolean setMaxImmortalIfFeasible(long maximum)
	{
		//TODO: stub
		if(maximum < 0) throw new IllegalArgumentException();
//		...
		maxImmortal = maximum;
		return true;
	}
	
	public boolean setMaxMemoryAreaIfFeasible(long maximum)
	{
		//TODO: stub
		if(maximum < 0) throw new IllegalArgumentException();
//		...
		maxMemoryArea = maximum;
		return true;
	}
}
